********************************************************************************
********************************************************************************
/*
In this replication set, you can find the code and the data that were used to perform 
all analyses in our article.

Enjoying the fruit of development? Working conditions and the earnings of low-skilled 
internal migrants in China across two decades (1993-2015)
doi:10.1080/1369183X.2022.2074380

1.replication files structure
The replication file(Stata do file) only runs if your using the intended 
folder structure and if you specify the macros referring to the differents 
folders such that they match with the location on your storage. 
You can set global macro path to adapt your own computer. 

2.data sources
We use two data sources in this article. 

The first data source is China Health and Nutrition Survey(CHNS). 
It can be obtained by request through the official website: 
https://www.cpc.unc.edu/ 
This dataset contains 12 files, including
(1)surveys_pub_12
(2)mast_pub_12
(3)rst_12
(4)educ_12
(5)jobs_12
(6)wages_12
(7)hhinc_10
(8)indinc_10
(9)wed_12
(10)ins_12
(11)relationmast_pub_00
(12)asset_12
All raw files must be placed in the "~\CHNS project\01_data\01_CHNS" floder. 
If they are named correctly, running the master-dofile should replicate our 
results in the figures and tables folder.

The second data sources is demographic and socio-economic index of China provinces.
All those data has been sorted out in the "~\CHNS project\01_data\01_CHNS" floder. 

3.statistic software
Furthermore, we need Stata 16.0 or higher version to replicate our analysis.
Stata 16.0 can directly read SAS file, which was original format provided by CHNS. 
If you use other software to convert SAS file to Stata file, most of our analysis 
can be performed via Stata 15.1.

If you require any help for replication, feel free to contact me.
Jing Lin
Nanjing University of Finance and Econimic
linjing@nufe.edu.cn
*/

*install modules used in our analysis
foreach i in renames ice logout misum xml_tab esttab {
	ssc install `i', replace 
}

*set global path
global mypath "~your_own_path\"

*set do files path
global analysis "${mypath}CHNS_project\02_do_files\"

*The first part is the comparison between migrants and urban residents
*merge all raw data
do "${analysis}01_merge_relevant_datasets.do"

*calculate Household Assert Index(HAI)
do "${analysis}02_calculate_HAI.do"

*clean up the raw data
do "${analysis}03_sort_out_relevant_variables.do"

*multiple imputation of missing value
*Note that this section will run for MORE THAN 20 hours. Please be patient.
do "${analysis}04_imputation.do"

*create table 1
do "${analysis}05_table_1.do"

*create table 2
do "${analysis}06_table_2.do"

*create table 3-5
do "${analysis}07_table_3_5.do"

*create appendix table 1-3
do "${analysis}08_appendix_table_1_3.do"

*create appendix table 4
do "${analysis}09_appendix_table_4.do"

*creat appendix table 5
do "${analysis}10_appendix_table_5.do"

*creat appendix table 6
do "${analysis}11_appendix_table_6.do"

*creat appendix table 7
do "${analysis}12_appendix_table_7.do"

*creat appendix table 8
do "${analysis}13_appendix_table_8.do"


